﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"         
                exclude-result-prefixes="msxsl"
>
  <xsl:output method="text" indent="no"  omit-xml-declaration="yes"    />

  <xsl:variable name="delimiter" select="','" />
  <xsl:variable name="qualifier" >&apos;</xsl:variable>
  <xsl:variable name="datafimename" select="'data.dat'" />

  <xsl:template name="inqualifier" ><xsl:param name="value" />
    <xsl:value-of select="$qualifier"/><xsl:value-of select="$value"/><xsl:value-of select="$qualifier"/>
  </xsl:template>
  
  <xsl:template match="/AllNomenclatures" ><xsl:call-template name="header" />
    <xsl:call-template name="variables" />
    <xsl:call-template name="variables_prop_labels" />
    <xsl:call-template name="variables_prop_val_labels" />
    <xsl:call-template name="variables_levels" />
  </xsl:template>

<xsl:template name="header">SET UNICODE=ON.
GET DATA
/TYPE=TXT
/FILE=<xsl:call-template name="inqualifier">
  <xsl:with-param name="value" select="'data.dat'" />
</xsl:call-template>
/DELCASE=LINE
/DELIMITERS="<xsl:value-of select="$delimiter"/>"
/QUALIFIER="<xsl:value-of select="$qualifier"/>"
/ARRANGEMENT=DELIMITED
/FIRSTCASE=1
/IMPORTCASE=ALL</xsl:template>

<xsl:template name="variables">
/VARIABLES=<xsl:for-each select="Factors/Factor">
  VFAC<xsl:value-of select="FactorID"/>  A255</xsl:for-each><xsl:for-each select="Practices/AgilePractice">
  VPRC<xsl:value-of select="PracticeID"/>  A255</xsl:for-each>.
CACHE.
EXECUTE.</xsl:template>

<xsl:template name="variables_prop_labels">
<xsl:for-each select="Factors/Factor" xml:space="preserve">
VARIABLE LABELS VFAC<xsl:value-of select="FactorID"/>  <xsl:call-template name="inqualifier"><xsl:with-param name="value" select="Name" /></xsl:call-template>.</xsl:for-each><xsl:for-each select="Practices/AgilePractice" xml:space="preserve" >
VARIABLE LABELS VPRC<xsl:value-of select="PracticeID"/>  <xsl:call-template name="inqualifier"><xsl:with-param name="value" select="Name" /></xsl:call-template>.</xsl:for-each></xsl:template>


<xsl:template name="variables_prop_val_labels">
<xsl:for-each select="Factors/Factor" xml:space="preserve" >
VALUE LABELS VFAC<xsl:value-of select="FactorID"/> <xsl:call-template name="variables_prop_val_labels_factors"><xsl:with-param name="id" select="FactorID" /></xsl:call-template></xsl:for-each><xsl:for-each select="Practices/AgilePractice" xml:space="preserve" >
VALUE LABELS VPRC<xsl:value-of select="PracticeID"/> <xsl:call-template name="variables_prop_val_labels_practices"><xsl:with-param name="id" select="PracticeID" /></xsl:call-template></xsl:for-each></xsl:template>

<xsl:template name="variables_prop_val_labels_factors"><xsl:param name="id" />
<xsl:for-each select="//Scales/FactorScale[FactorID=$id]">
  "<xsl:value-of select="Order"/>" "<xsl:value-of select="Value"/>"</xsl:for-each>.</xsl:template>

<xsl:template name="variables_prop_val_labels_practices">
<xsl:param name="id" />
<xsl:for-each select="//PracticeValues/PracticeUsingValue">
  "<xsl:value-of select="RawValue"/>" "<xsl:value-of select="Value"/>"</xsl:for-each>.</xsl:template>
  
<xsl:template name="variables_levels">
VARIABLE LEVEL <xsl:call-template name="variables_levels_factors_ordinal"/>(ORDINAL) /<xsl:call-template name="variables_levels_factors_nominal"/>(NOMINAL).</xsl:template>

<xsl:template name="variables_levels_factors_nominal" xml:space="preserve" >
  <xsl:for-each select="Factors/Factor[ScaleType='true']">VFAC<xsl:value-of select="FactorID"/> </xsl:for-each>
</xsl:template>
  
<xsl:template name="variables_levels_factors_ordinal"  xml:space="preserve" >
  <xsl:for-each select="Factors/Factor[ScaleType='false']">VFAC<xsl:value-of select="FactorID"/> </xsl:for-each>
  <xsl:for-each select="Practices/AgilePractice">VPRC<xsl:value-of select="PracticeID"/> </xsl:for-each></xsl:template>
</xsl:stylesheet>
